package com.itheima.consumer;

import com.itheima.consumer.config.MyRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;

/**
 * 使用Ribbon的步骤
 * 1 RestTemplate加上注解@LoadBalanced
 * 2 由于使用了负载均衡,所以ip和端口由Ribbon负责,我们需要替换成提供者application.yml中的spring.application.name的值
 * 3 配置负载均衡策略 默认 轮询
 * 注解方式 启动类加上@RibbonClient(name = "提供者的spring.application.name",configuration = 策略类名称.class)
 * yml
 * EUREKA-PROVIDER:
 *   ribbon:
 *     NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
 */
@EnableDiscoveryClient // 激活DiscoveryClient
@EnableEurekaClient
@SpringBootApplication
// name  : 那个服务 负载均衡, 策略是那个
@RibbonClient(name = "EUREKA-PROVIDERE",configuration = MyRule.class)
public class ConsumerApp {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApp.class,args);
    }
}
